package cn.dengta.webapp.user.model;

import java.util.*;
import java.util.stream.Collectors;

import cn.dengta.common.model.ValueProxy;
import cn.dengta.common.model.ValueProxyImpl;
import cn.dengta.common.util.Common;
import cn.dengta.webapp.user.entity.userLevel.UserLevelRule.UserLevelRuleType;
import lombok.Getter;
import me.codeplayer.util.CollectionUtil;
import me.codeplayer.util.X;

/**
 * 专题种类
 */
@Getter
public enum UserLevelRuleCategory implements ValueProxyImpl<UserLevelRuleCategory, Integer> {
	/** 活跃 */
	ACTIVE(0, "活跃", true),
	/** 财富 */
	WEALTH(1, "财富", true),
	//
	;

	// 定义私有变量
	public final Integer value;
	public final boolean show;
	final ValueProxy<UserLevelRuleCategory, Integer> proxy;

	// 构造函数，枚举类型只能为私有
	UserLevelRuleCategory(Integer value, String label, boolean show) {
		this.value = value;
		this.show = show;
		this.proxy = new ValueProxy<>(this, ordinal(), label);
	}

	public static final UserLevelRuleCategory[] getValues() {
		return ValueProxy.getCachedArray(UserLevelRuleCategory.class, UserLevelRuleCategory::values);
	}

	public static UserLevelRuleCategory of(Integer value) {
		return ACTIVE.getValueOf(value);
	}

	public static List<UserLevelRuleCategory> subtype;

	public static List<UserLevelRuleCategory> subtype() {
		List<UserLevelRuleCategory> types = subtype;
		if (!X.isValid(types)) {
			types = Arrays.stream(getValues()).filter(UserLevelRuleCategory::isShow).collect(Collectors.toList());
			Common.replaceListValues(types, type -> {
				final Map<String, Object> map = CollectionUtil.ofHashMap("value", type.getValue(), "label", type.getLabel());
				X.use(UserLevelRuleType.find(type), c -> map.put("subtype", c));
				return map;
			});
			subtype = types;
		}
		return types;
	}

}
